package first.program;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class MasterMindActivity extends Activity {
    protected static final int feedbackConstant = 3;
    public static final String PREFS_NAME = "MyPrefsFile"; // Shared Preference File
	/** Called when the activity is first created. */
    
    
	int pwLength = 4; //Length of the pass code
	String passcode[]= new String[pwLength];
	String colors[] = {"green", "orange", "black", "blue","red", "purple","yellow","gray"};
	Boolean rand_setting;
	final CreateGame game = new CreateGame();
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        final SharedPreferences settings= getSharedPreferences(PREFS_NAME, 0);
        rand_setting = settings.getBoolean("rand", false);
      //  Log.i("MasterMindActivity", "rand_setting is "+rand_setting);
        
        
        Button multiplayer = (Button) findViewById(R.id.multiplayer);
        multiplayer.setOnClickListener(new View.OnClickListener() {
        	
            public void onClick(View view) {
            	view.performHapticFeedback(feedbackConstant , 0);
                Intent myIntent = new Intent(view.getContext(), CodeScreen.class);
                startActivityForResult(myIntent, 0);
                
            }

        });
        
        Button single = (Button) findViewById(R.id.singleplayer);
        single.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
            	view.performHapticFeedback(feedbackConstant , 0);
            	rand_setting = settings.getBoolean("rand", false);
            
            	
            	if(rand_setting){
            	Log.i("MasterMindActivity", "Repeats are allowed");
            	game.createRep();
            	passcode = game.getPassword();          	
            	}
            else{
            		Log.i("MasterMindActivity", "wrong! repeats not allowed");
            		game.createNonRep();
                	passcode = game.getPassword();

            	}
            		
                Intent myIntent = new Intent(view.getContext(), GameScreen.class);
                myIntent.putExtra("passcode", passcode);
                myIntent.putExtra("mode", 1);
                startActivityForResult(myIntent, 0);
            }
            

        });
        
        Button pref = (Button) findViewById(R.id.prefbut);
        pref.setOnClickListener(new View.OnClickListener() {
        	
            public void onClick(View view) {
            	view.performHapticFeedback(feedbackConstant , 0);
                Intent myIntent = new Intent(view.getContext(), PrefScreen.class);
                startActivityForResult(myIntent, 0);
                
            }

        });

    }
    @Override
    public void onBackPressed(){
    return;	
    }
}
